package com.qf.business.redevnlopes.core.application;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * author Ken
 * create_time 2022/9/29
 */
@Configuration
public class XxlJobConfiguration {

    /**
     * 配置实体
     */
    @Data
    @ConfigurationProperties(prefix = "xxl.job.executor")
    @Component
    public static class XxlJobConfig{
        @Value("${xxl.job.admin.address}")
        private String adminAddresses;
        private String accessToken;
        private String appname;
        private String address;
        private String ip;
        private int port;
        private String logPath;
        private int logRetentionDays;
    }

    @Autowired
    private XxlJobConfig xxlJobconfig;

    @Bean
    public XxlJobSpringExecutor getXxlJobExecutor(){
        XxlJobSpringExecutor executor = new XxlJobSpringExecutor();
        executor.setAdminAddresses(xxlJobconfig.getAdminAddresses());
        executor.setAppname(xxlJobconfig.getAppname());
        executor.setIp(xxlJobconfig.getIp());
        executor.setPort(xxlJobconfig.getPort());
        executor.setAccessToken(xxlJobconfig.getAccessToken());
        executor.setLogPath(xxlJobconfig.getLogPath());
        executor.setLogRetentionDays(xxlJobconfig.getLogRetentionDays());
        return  executor;
    }
}
